package com.iyeed.jbpm03.demo09.superstate;

import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import org.junit.Test;

public class SuperStateTest {

	
	@Test
	public void testSuperStateProcess() {
		JbpmContext jcontext = JbpmConfiguration.getInstance().createJbpmContext();
		try {
			ProcessDefinition pd = jcontext.getGraphSession().findLatestProcessDefinition("superstateprocess");
			ProcessInstance pi = pd.createProcessInstance();
			Token token = pi.getRootToken();
			
			//Token路由到state1节点，并进入super state1
			token.signal();
			System.out.println("当前流程所在的节点名：" + token.getNode().getName());
			
			//Token离开state1节点，同时也离开super state1进入super state2，停留于state2节点
			token.signal();
			System.out.println("当前流程所在的节点名：" + token.getNode().getName());
			
			//Token离开state2节点，同时进入super state3节点，停留于state3
			token.signal();
			System.out.println("当前流程所在的节点名：" + token.getNode().getName());
			
			//离开state3，停留于state4
			token.signal();
			System.out.println("当前流程所在的节点名：" + token.getNode().getName());
			
			//离开state4，同是离开super state3，停留于state5
			token.signal();
			System.out.println("当前流程所在的节点名：" + token.getNode().getName());
			
			//离开state5，同时离开super state2，停留于end state
			token.signal();
			System.out.println("当前流程所在的节点名：" + token.getNode().getName());
		} finally {
			jcontext.close();
		}
	}
	
}
